﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSS_XNA.Engine.Error;
using DSS_XNA.Engine.Script;

namespace DSS_XNA.Engine.Script.Commands
{
    public class ScriptCommand_LevelTime
    {
        #region Static Methods

        public static void Action(Dictionary<string, string> args, ScriptManager manager, Game1 engine)
        {
            if (!args.ContainsKey("action"))
                throw new DSSException("No Action parameter for AddEvent");

            string action = manager.GetParameterValue(args["action"]).ToString();

            action = action.ToLower().Trim();

            if (action == "start")
            {
                engine.CurrentWorld.CurrentWorld.LevelTimer.Start();
            }
            else if (action == "stop")
            {
                engine.CurrentWorld.CurrentWorld.LevelTimer.Stop();
            }
            else if (action == "pause")
            {
                engine.CurrentWorld.CurrentWorld.LevelTimer.Pause();
            }
            else if (action == "resume")
            {
                engine.CurrentWorld.CurrentWorld.LevelTimer.Resume();
            }
            else if (action == "reset")
            {
                engine.CurrentWorld.CurrentWorld.LevelTimer.Reset();
            }
            else if (action == "add")
            {
                if (!args.ContainsKey("time"))
                    throw new DSSException("No Time parameter for LevelTime with action: add");
                int milliseconds = Convert.ToInt32(manager.GetParameterValue(args["time"]));

                engine.CurrentWorld.CurrentWorld.LevelTimer.Add(new TimeSpan(0, 0, 0, 0, milliseconds));
            }
            else if (action == "subtract")
            {
                if (!args.ContainsKey("time"))
                    throw new DSSException("No Time parameter for LevelTime with action: add");
                int milliseconds = Convert.ToInt32(manager.GetParameterValue(args["time"]));

                engine.CurrentWorld.CurrentWorld.LevelTimer.Subtract(new TimeSpan(0, 0, 0, 0, milliseconds));
            }
            else
            {
                throw new DSSException(String.Format("Unknown LevelTime action: {0}", action));
            }
        }

        #endregion
    }
}
